package com.example.blog.common;


import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor // 无参的构造方法
@AllArgsConstructor // 全参数的构造方法
public class Result<T> {
    @ApiModelProperty(value = "状态码", example = "1")
    private Integer code;

    @ApiModelProperty("状态码描述")
    private String msg;

    @ApiModelProperty("返回数据信息")
    private T data;

    public Result<T> success(){
        return new Result<T>(200,"操作成功",null);
    }


    public Result<T> success(T data){
        return new Result<T>(200,"操作成功",data);
    }


    public Result<T> error(String msg){
        return new Result<T>(500,msg,null);
    }

    public  Result<T> error(Integer code,String msg){
        return new Result<T>(code,msg,null);
    }

    public Result<T> error(){
        return new Result<T>(500,"系统错误，请联系管理员",null);
    }

}
